package com.itheima;

import javax.swing.*;
import java.awt.*;

public class GamePanel extends JPanel {
    public GamePanel() {
        this.setSize(Global.WIDTH * Global.CELL_SIZE, Global.HEIGHT * Global.CELL_SIZE);
    }

    private Ground ground;
    private Shape shape;

    public void display(Ground ground, Shape shape) {
        System.out.println("GamePanel's display");
        this.ground = ground;
        this.shape = shape;
        this.repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        if (shape != null && ground != null) {
            shape.drawMe(g);
            ground.drawMe(g);

        }
    }
}
